#!/bin/csh -f

touch mus-config.h
# mus-config.h needed by tcc
cp tools/ffitest.c .
cp tools/tauto.scm .
cp ~/cl/t923.scm .
cp ~/cl/t101.scm .
cp tools/*.scm .
# cp ~/cl/make-repl .
cp ~/cl/low-primes.scm .
cp ~/cl/full-s7test.scm .
cp ~/cl/lt.scm .
cp ~/cl/peak-phases.scm .
cp ~/cl/arbtest.scm .
cp ~/cl/threads.c .

echo ' '
echo '-------- base case --------'
echo ' '
gcc s7.c -c -I. -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
echo ' '
repl -e '(define full-s7test #t)' s7test.scm
echo ' '
repl tauto.scm
echo ' '

echo ' '
echo '-------- g++ -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough --------'
echo ' '
g++ s7.c -c -I. -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -ldl -lm -Wl,-export-dynamic
g++ -o repl repl.c -g -O2 -Wall -Wextra s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- base case + nrepl --------'
echo ' '
gcc s7.c -c -I. -g3 -ldl -lm -Wl,-export-dynamic
gcc -o nrepl nrepl.c -g3 -Wall s7.o -I. -Wl,-export-dynamic -lnotcurses-core -lm -ldl
nrepl s7test.scm

echo ' '
echo '-------- with-gmp --------'
echo ' '
gcc s7.c -c -I. -g3 -DWITH_GMP=1 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lgmp -lmpfr -lmpc -lm -ldl -Wl,-export-dynamic
rm *.so
repl s7test.scm
echo ' '
# repl t101.scm

echo ' '
echo '-------- with-gmp + g++ --------'
echo ' '
g++ s7.c -c -I. -g3 -DWITH_GMP=1 -Wall -ldl -lm -Wl,-export-dynamic
g++ -o repl repl.c -g3 -Wall s7.o -I. -lgmp -lmpfr -lmpc -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- with-gmp precision --------'
echo ' '
gcc s7.c -c -I. -g3 -DWITH_GMP=1 -DDEFAULT_BIGNUM_PRECISION=512 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lgmp -lmpfr -lmpc -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- libarb/flint --------'
echo ' '
gcc s7.c -c -I. -g3 -DWITH_GMP=1 -DDEFAULT_BIGNUM_PRECISION=512 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lgmp -lmpfr -lmpc -lm -ldl -Wl,-export-dynamic
gcc -fPIC -c libarb_s7.c
gcc libarb_s7.o -shared -o libarb_s7.so -L/usr/local/lib -lflint
repl arbtest.scm
rm *.so

echo ' '
echo '-------- s7-debugging/system-extras --------'
echo ' '
gcc s7.c -c -I. -DS7_DEBUGGING -DWITH_SYSTEM_EXTRAS -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
echo ' '
repl t101.scm

echo ' '
echo '-------- with-pure-s7 --------'
echo ' '
gcc s7.c -c -I. -DWITH_PURE_S7 -Wall -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
echo ' '
repl -e '(define full-s7test #t)' s7test.scm

echo ' '
echo '-------- with-history --------'
echo ' '
gcc s7.c -c -I. -DWITH_HISTORY -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- with-history size --------'
echo ' '
gcc s7.c -c -I. -DWITH_HISTORY -DDEFAULT_HISTORY_SIZE=32 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- initial sizes --------'
echo ' '
gcc s7.c -c -I. -Wall -g3 -DINITIAL_HEAP_SIZE=32768 -DINITIAL_STACK_SIZE=512 -DINITIAL_PROTECTED_OBJECTS_SIZE=4 -DGC_TEMPS_SIZE=512 -DSYMBOL_TABLE_SIZE=10009 -DNUM_SMALL_INTS=256 -DINITIAL_RECUR_STACK_SIZE=32 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- optimized/disable-deprecated --------'
echo ' '
gcc s7.c -c -I. -O2 -g -DDISABLE_DEPRECATED -fomit-frame-pointer -funroll-loops -Wall -march=native -ldl -lm -Wl,-export-dynamic 
gcc -o repl repl.c -g -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
echo ' '
repl -e '(define full-s7test #t)' s7test.scm

echo ' '
echo '-------- with-main --------'
echo ' '
gcc s7.c -o repl -DWITH_MAIN -DUSE_SND=0 -I. -g3 -Wall -ldl -lm -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- max-string-input --------'
echo ' '
gcc s7.c -c -I. -DMAX_SIZE_FOR_FILE_TO_STRING_PORT_CONVERSION=128 -DDEFAULT_PRINT_LENGTH=8 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl -e '(define full-s7test #t)' s7test.scm

echo ' '
echo '-------- number-separator --------'
echo ' '
gcc s7.c -c -I. -DWITH_NUMBER_SEPARATOR=1 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- have-overflow-checks --------'
echo ' '
gcc s7.c -c -I. -DHAVE_OVERFLOW_CHECKS=0 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- disable-autoload and system-extras --------'
echo ' '
gcc s7.c -c -I. -DDISABLE_AUTOLOAD=1 -DWITH_SYSTEM_EXTRAS=0 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- silly stuff --------'
echo ' '
gcc s7.c -c -I. -DEXTRA_EXPONENT_MARKERS=1 -DS7_ALIGNED=1 -DWITH_VECTORIZE=0 -DWITH_MULTITHREAD_CHECKS=0 -DWITH_DTOA=0 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- more silly stuff --------'
echo ' '
gcc s7.c -c -I. -DWITH_WARNINGS=0 -DGC_TEMPS_SIZE=32 -DGC_TRIGGER_SIZE=32 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- gc 0.5 --------'
echo ' '
gcc s7.c -c -I. -DGC_RESIZE_HEAP_FRACTION=0.5 -DOUTPUT_PORT_DATA_SIZE=128 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- gc 0.6 --------'
echo ' '
gcc s7.c -c -I. -DGC_RESIZE_HEAP_FRACTION=0.6 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- gc 0.7 --------'
echo ' '
gcc s7.c -c -I. -DGC_RESIZE_HEAP_FRACTION=0.7 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- gc 0.8 --------'
echo ' '
gcc s7.c -c -I. -DGC_RESIZE_HEAP_FRACTION=0.8 -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- disable-file-output (compilation only) --------'
echo ' '
gcc s7.c -c -I. -DDISABLE_FILE_OUTPUT=1 -g3 -Wall -ldl -lm -Wl,-export-dynamic
# gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
# repl s7test.scm

echo ' '
echo '-------- valgrind --------'
echo ' '
gcc s7.c -c -I. -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
valgrind repl s7test.scm
echo ' '
valgrind repl -e '(define full-s7test #t)' s7test.scm

gcc -o nrepl s7.c -O2 -I. -Wl,-export-dynamic -lm -ldl -DWITH_MAIN -DWITH_NOTCURSES -lnotcurses-core

echo ' '
echo '-------- tcc --------'
echo ' '
tcc -o repl s7.c -I. -g3 -lm -DWITH_MAIN -ldl -rdynamic -DWITH_C_LOADER -DS7_DEBUGGING
repl s7test.scm

echo ' '
echo '-------- fortify flags --------'
echo ' '
gcc -o repl s7.c -O2 -I. -g -DWITH_MAIN -Wl,-export-dynamic -lm -ldl -DWITH_C_LOADER -Wall -Wformat=2 -Wtrampolines -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -fstack-clash-protection -fstack-protector-strong -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fcf-protection=full
repl s7test.scm

echo ' '
echo '-------- main version --------'
echo ' '
gcc s7.c -c -DS7_DEBUGGING=1 -DWITH_HISTORY=1 -DGSL_DISABLE_DEPRECATED -DDISABLE_DEPRECATED -Wall -Wextra -I. -g3 -Wduplicated-cond -Wlogical-op -Wjump-misses-init -Wfatal-errors -Wformat -Wno-implicit-fallthrough -Wpointer-arith -Wduplicated-branches -Wdangling-else -Wno-unused-parameter -Wunused-function -DTRAP_SEGFAULT -DS7_ALIGNED=1 -DINITIAL_HEAP_SIZE=6400 -DNUM_SMALL_INTS=256 -DWITH_NUMBER_SEPARATOR -DWITH_IMMUTABLE_UNQUOTE=1 -Wunreachable-code -Wstrict-aliasing -Wcast-align -Wmissing-declarations -Wmissing-include-dirs -Wuninitialized -Wwrite-strings -Wdouble-promotion
gcc -o repl repl.c -g3 -Wall s7.o -I. -Wl,-export-dynamic -lm -ldl
repl s7test.scm

echo ' '
echo '-------- fsanitize=undefined --------'
echo ' '
gcc s7.c -c -I. -g3 -DS7_ALIGNED=1 -Wall -ldl -lm -Wl,-export-dynamic -fsanitize=undefined
gcc -o repl repl.c -g3 -Wall s7.o -DS7_ALIGNED=1 -I. -lm -ldl -Wl,-export-dynamic -fsanitize=undefined
# repl -e '(define asan-flags "-fsanitize=undefined")' s7test.scm
repl -e '(begin (define asan-flags "-fsanitize=undefined") (define full-s7test #t))' s7test.scm
# repl -e '(define asan-flags "-fsanitize=undefined -fno-sanitize-recover")' s7test.scm

echo ' '
echo '-------- fsanitize=address --------'
echo ' '
gcc s7.c -c -I. -g3 -Wall -ldl -lm -Wl,-export-dynamic -fsanitize=address
gcc -o repl repl.c -g3 -Wall s7.o -DS7_ALIGNED=1 -I. -lm -ldl -Wl,-export-dynamic -fsanitize=address
# repl -e '(define asan-flags "-fsanitize=address")' s7test.scm
repl -e '(begin (define asan-flags "-fsanitize=address") (define full-s7test #t))' s7test.scm

echo ' '
echo '-------- threads --------'
echo ' '
gcc s7.c -c -I. -g3 -Wall -ldl -lm -Wl,-export-dynamic
gcc -o threads threads.c s7.o -O -g -Wl,-export-dynamic -pthread -lm -I. -ldl
threads

echo ' '
echo '-------- clang --------'
echo ' '
clang s7.c -c -I. -O -g -Wall -Wextra -Wno-unused-parameter
clang -o repl repl.c -I. -O2 -g s7.o -ldl -lm -Wl,-export-dynamic
repl s7test.scm
